#! /usr/bin/env bash

BUILDIFIER_SHORT_PATH=@@BUILDIFIER_SHORT_PATH@@
ARGS=@@ARGS@@

buildifier_short_path=$(readlink "$BUILDIFIER_SHORT_PATH")
(cd "$BUILD_WORKSPACE_DIRECTORY" \
     && find . \
             -type f \
             @@EXCLUDE_PATTERNS@@ \
             \( -name '*.bzl' \
                -o -name '*.sky' \
                -o -name BUILD.bazel \
                -o -name BUILD \
                -o -name '*.BUILD' \
                -o -name 'BUILD.*.bazel' \
                -o -name 'BUILD.*.oss' \
                -o -name WORKSPACE \
                -o -name WORKSPACE.bazel \
                -o -name WORKSPACE.oss \
                -o -name 'WORKSPACE.*.bazel' \
                -o -name 'WORKSPACE.*.oss' \) \
             -print \
        | xargs "$buildifier_short_path" "${ARGS[@]}")
